var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (e, i) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, e) {
              t.__proto__ = e;
            }) ||
          function (t, e) {
            for (var i in e)
              Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]);
          })(e, i);
      };
      return function (e, i) {
        function a() {
          this.constructor = e;
        }
        if ("function" != typeof i && null !== i)
          throw new TypeError(
            "Class extends value " + String(i) + " is not a constructor or null"
          );
        t(e, i),
          (e.prototype =
            null === i
              ? Object.create(i)
              : ((a.prototype = i.prototype), new a()));
      };
    })(),
  MTPitchItemView = (function (t) {
    function e() {
      var e = t.call(this) || this;
      return (
        (e.dataArr = []),
        (e.item_type = -1),
        (e.spaceTime = 0),
        e.btn_pitchBack.on(Laya.Event.CLICK, e, e.onPitchBackDidClickFn),
        (e.tab_pitchItem.selectHandler = new Laya.Handler(
          e,
          e.onTabPitchItemSelectFn
        )),
        (e.list_pitch_wupin.selectEnable = !0),
        (e.list_pitch_wupin.vScrollBarSkin = ""),
        e.list_pitch_wupin.on(Laya.Event.CLICK, e, e.setPitchItemSelected),
        (e.list_pitch_wupin.scrollBar.changeHandler = new Handler(
          e,
          e.onLoadMoreSendGoodsData
        )),
        WebSocketService.addListener({
          caller: e,
          code: 1316,
          method: e.onPitchItemKuangshiFn,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1322,
          method: e.onPitchItemKuangshiFn,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1323,
          method: e.onPitchItemKuangshiFn,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1324,
          method: e.onPitchItemKuangshiFn,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1419,
          method: e.onPitchItemKuangshiFn,
        }),
        Laya.stage.on("HomePageView", e, e.eventHandler),
        e
      );
    }
    return (
      __extends(e, t),
      (e.openView = function (t) {
        null == this.pitchItemVC && (this.pitchItemVC = new e()),
          (this.pitchItemVC.item_pos = t),
          this.pitchItemVC.pos(0, 35),
          Laya.stage.addChild(this.pitchItemVC),
          (this.pitchItemVC.currentPage = 0),
          (this.pitchItemVC.dataArr = []),
          (this.pitchItemVC.tab_pitchItem.selectedIndex = 0),
          WebSocketService.send({ c: 1316, d: { pageNum: 0 } });
      }),
      (e.prototype.onTabPitchItemSelectFn = function (t) {
        (this.item_type = t),
          0 == t
            ? WebSocketService.send({ c: 1316, d: { pageNum: 0 } })
            : 1 == t
            ? WebSocketService.send({ c: 1322, d: { pageNum: 0 } })
            : 2 == t
            ? WebSocketService.send({ c: 1323, d: { pageNum: 0 } })
            : 3 == t
            ? WebSocketService.send({ c: 1324, d: { pageNum: 0 } })
            : 4 == t &&
              WebSocketService.send({ c: 1419, d: { action: 0, pageNum: 0 } }),
          this.list_pitch_wupin.scrollTo(0),
          (this.dataArr = []),
          (this.currentPage = 0);
      }),
      (e.prototype.onPitchItemKuangshiFn = function (t) {
        if (0 == t.code) {
          if (this.currentPage >= 1) {
            if (0 == t.list.length) return void this.currentPage--;
            for (a = 0; a < t.list.length; a++) {
              var e = t.list[a];
              this.dataArr.push(e), (this.dataSource = []);
            }
          } else (this.dataArr = t.list), (this.dataSource = []);
          this.dataArr.length > 0 && (this.list_pitch_wupin.visible = !0),
            (this.isloading = !1);
          var i;
          if (1323 == t.act_id)
            for (a = 0; a < this.dataArr.length; a++)
              (i = {
                pitchname: {
                  text: this.dataArr[a].name + " (" + this.dataArr[a].num + ")",
                },
                pitchaddButton: { label: "添加" },
                pitchTitle: this.dataArr[a].name,
                pitchSum: this.dataArr[a].num,
                pitchID: this.dataArr[a].id,
                pitchType: this.dataArr[a].type,
              }),
                this.dataSource.push(i);
          else if (1316 == t.act_id)
            for (a = 0; a < this.dataArr.length; a++)
              (i = {
                pitchname: {
                  text: this.dataArr[a].name + " (" + this.dataArr[a].num + ")",
                },
                pitchaddButton: { label: "添加" },
                pitchTitle: this.dataArr[a].name,
                pitchSum: this.dataArr[a].num,
                pitchID: this.dataArr[a].id,
              }),
                this.dataSource.push(i);
          else if (1322 == t.act_id)
            for (a = 0; a < this.dataArr.length; a++)
              (i = {
                pitchname: {
                  text:
                    this.dataArr[a].name + " (" + this.dataArr[a].level + "级)",
                },
                pitchaddButton: { label: "添加" },
                pitchTitle: this.dataArr[a].name,
                pitchSum: 1,
                pitchID: this.dataArr[a].id,
              }),
                this.dataSource.push(i);
          else if (1324 == t.act_id)
            for (a = 0; a < this.dataArr.length; a++)
              (i = {
                pitchname: {
                  text: this.dataArr[a].name + " (" + this.dataArr[a].num + ")",
                },
                pitchaddButton: { label: "添加" },
                pitchTitle: this.dataArr[a].name,
                pitchSum: this.dataArr[a].num,
                pitchID: this.dataArr[a].id,
              }),
                this.dataSource.push(i);
          else if (1419 == t.act_id)
            for (var a = 0; a < this.dataArr.length; a++)
              (i = {
                pitchname: {
                  text:
                    this.dataArr[a].name + " (Lv" + this.dataArr[a].lvl + "级)",
                },
                pitchaddButton: { label: "添加" },
                pitchTitle: this.dataArr[a].name,
                pitchSum: 1,
                pitchID: this.dataArr[a].id,
              }),
                this.dataSource.push(i);
          this.list_pitch_wupin.dataSource = this.dataSource;
        }
      }),
      (e.prototype.setPitchItemSelected = function (t) {
        if ("pitchaddButton" == t.target.name && this.dataArr) {
          var e = this.list_pitch_wupin.selectedItem;
          if (e) {
            var i = {
              chargeID: e.pitchID,
              chargeTitle: e.pitchTitle,
              chargeSum: e.pitchSum,
              chargeType: this.tab_pitchItem.selectedIndex,
              chargePos: this.item_pos,
              stoneType: e.pitchType ? e.pitchType : 0,
            };
            MTPitchChargeView.open(i);
          }
        }
      }),
      (e.prototype.eventHandler = function (t) {
        t && "close" == t && this.removeSelf();
      }),
      (e.prototype.onLoadMoreSendGoodsData = function (t) {
        var e = t / this.list_pitch_wupin.scrollBar.max,
          i = new Date(),
          a = !1;
        if (
          (i.getTime() - this.spaceTime >= 3e3 && (a = !0),
          1 == e && 0 == this.isloading && a)
        )
          return (
            (this.isloading = !0),
            this.currentPage++,
            0 == this.tab_pitchItem.selectedIndex
              ? WebSocketService.send({
                  c: 1316,
                  d: { pageNum: this.currentPage },
                })
              : 1 == this.tab_pitchItem.selectedIndex
              ? WebSocketService.send({
                  c: 1322,
                  d: { pageNum: this.currentPage },
                })
              : 2 == this.tab_pitchItem.selectedIndex
              ? WebSocketService.send({
                  c: 1323,
                  d: { pageNum: this.currentPage },
                })
              : 3 == this.tab_pitchItem.selectedIndex
              ? WebSocketService.send({
                  c: 1324,
                  d: { pageNum: this.currentPage },
                })
              : 4 == this.tab_pitchItem.selectedIndex &&
                WebSocketService.send({
                  c: 1419,
                  d: { action: 0, pageNum: this.currentPage },
                }),
            void (this.spaceTime = i.getTime())
          );
      }),
      (e.prototype.onPitchBackDidClickFn = function () {
        this.removeSelf();
      }),
      e
    );
  })(ui.MarketController.MTPitchItemViewUI);
